//
//  StrTool.m
//  NewPro
//
//  Created by RYX on 2019/1/14.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "StrTool.h"

@implementation StrTool

#pragma mark - 时间戳转字符串
+ (NSString *)changeWithTime:(NSString *)timeStr{
    
    // iOS 生成的时间戳是10位
    NSTimeInterval interval  = [timeStr doubleValue] / 1000.0;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateString = [formatter stringFromDate: date];
    
    return dateString;
}

#pragma mark - //64编码
+ (NSString *)encodeBase64:(NSString *)string
{
    //先将string转换成data
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    
    NSData *base64Data = [data base64EncodedDataWithOptions:0];
    
    NSString *baseString = [[NSString alloc]initWithData:base64Data encoding:NSUTF8StringEncoding];
    
    return baseString;
}

#pragma mark - 获取时间戳
+ (NSString *)currentTimeStr{
    
    NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];//获取当前时间0秒后的时间
    NSTimeInterval time=[date timeIntervalSince1970] * 1000;// *1000 是精确到毫秒，不乘就是精确到秒
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time];
    return timeString;
}

#pragma mark - 获取富文本
+ (NSAttributedString *)getAttributedTextWithTitle:(NSString *)title color:(UIColor *)color fontSize:(CGFloat)size{
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Medium" size: size],NSForegroundColorAttributeName: color}];
    return string;
}

//判断是否为整形：
+ (BOOL)isPureInt:(NSString*)string{
    
    NSScanner* scan = [NSScanner scannerWithString:string];
    
    int val;
    
    return[scan scanInt:&val] && [scan isAtEnd];
    
}

//判断是否为浮点形：
+ (BOOL)isPureFloat:(NSString*)string{
    
    NSScanner* scan = [NSScanner scannerWithString:string];
    
    float val;
    
    return[scan scanFloat:&val] && [scan isAtEnd];
    
}



@end
